home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / C++ AppleLink Messages / CPlus.Dev$ 2⁄16⁄90 / 0053-C++ access control b-Feb90 < prev    next >
Encoding:
Text File  |  1990-02-16  |  1.4 KB  |  91 lines  |  [TEXT/GEOL]

  1. Item    5509806                         13-Feb-90        13:24PST
  2.  
  3. From:   D4695                           Skywalker Sys, Scott Collins,PRT
  4.  
  5. To:     CPLUS.DEV$                      C++ Interest List--Developers
  6.  
  7. Sub:    C++ access control bug
  8.  
  9. Hello,
  10.   the following complete program demonstrates what Neal Goldstien and I think
  11. is a bug in implementation of the C++ translator.
  12.  
  13. // == cut here ==========
  14.  
  15.  
  16. #include <iostream.h>
  17.  
  18. class A
  19.    {
  20.    public:
  21.    A( char *name );
  22.  
  23.    char *Name();
  24.    void legal();
  25.    void illegal( A& a );
  26.  
  27.    private:
  28.    void g( A *caller );
  29.  
  30.    private:
  31.    char *fName;
  32.    };
  33.  
  34. // ----------
  35.  
  36. inline A::A( char *name )
  37.    { fName = name; }
  38.  
  39. // ----------
  40.  
  41. inline char *A::Name()
  42.    { return fName; }
  43.  
  44. // ----------
  45.  
  46. void A::illegal( A& a )
  47.    {
  48.    a.g( this );
  49.    }
  50.  
  51. // ----------
  52.  
  53. void A::legal()
  54.    {
  55.    this->g( this );
  56.    }
  57.  
  58. // ----------
  59.  
  60. void A::g( A *caller )
  61.    {
  62.    cout << this->Name() << ".g() -- called by " << caller->Name() << endl;
  63.    }
  64.  
  65. // ----------
  66.  
  67. main()
  68.    {
  69.    A a1( "a1" );
  70.    A a2( "a2" );
  71.  
  72.    a1.legal();
  73.    a1.illegal( a2 );
  74.  
  75.    }
  76.  
  77. // == cut here ==========
  78.  
  79.   The output of this program (which compiles correctly) is --
  80.  
  81. a1.g() -- called by a1
  82. a2.g() -- called by a1
  83.  
  84. Both Neal and I previously assumed that private meant private to an object not
  85. private to a class.
  86.  
  87. Is this a bug and if so to whom should it be reported?
  88.  
  89.   -- Scott Collins
  90.  
  91.